package module.bitmap
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.geom.Point;
	import flash.utils.Dictionary;
	
	/**
	 * bitmap 播放器
	 * @author Quexi 
	 */	
	public class BitmapPlayer
	{
		public static var zeroPoint:Point = new Point(0, 0);
		public static var emptyBmd:BitmapData = new BitmapData(1,1);
		public static var playDely:int =3;
		
		private var _resID:String;
		/**
		 * 第几行动作 
		 */		
		protected var line:int = 3;
		private var _bitmapdata:BitmapData;
		
		private var _frame:uint = 0;
		private var _dely:int = 0;
		
		public function BitmapPlayer(resID:String)
		{
			_resID = resID;
			_bitmapdata = emptyBmd;
		}
		
		/**
		 * 播放动画 
		 */		
		public function play(line:int):void
		{
			if(this.line != line)
				_frame = 0;
			this.line = line;
			_dely ++;
			if(_dely > playDely)
			{
				if(_frame < AvatarInfoEnum.AVATAR_FRAME_MATRIX[line] - 1)
					_frame  ++;
				else _frame = 0;
				_dely = 0;
				rander();
			}
		}
		
		public function draw(drawer:BitmapData):void
		{
			(drawer as BitmapData).copyPixels(_bitmapdata, _bitmapdata.rect, zeroPoint);
		}
		
		/**
		 * 渲染一次 
		 */		
		public function rander():void
		{
			var resBmd:BitmapData = ResourceManager.getAnimationBmd(_resID, line, _frame);
			if(resBmd != null)
				_bitmapdata = resBmd;
			else _bitmapdata = emptyBmd;
		}
		
		public function set currentFrame(value:uint):void
		{
			_frame = value;
		}
		
		public function get currentFrame():uint
		{
			return _frame;
		}
		
		/**
		 * 显示内容 
		 */
		public function get bitmapdata():BitmapData
		{
			return _bitmapdata;
		}
		
		/**
		 *资源id 
		 */
		protected function get resID():String
		{
			return _resID;
		}
		
		
		protected function set resID(value:String):void
		{
			_resID = value;
		}
		
		
		//
	}
}